package com.ithema.edu.info.manager.service;

import com.ithema.edu.info.manager.BeanFactory;
import com.ithema.edu.info.manager.dao.OutherTeacherDao;

import com.ithema.edu.info.manager.domain.Teacher;

import java.util.ArrayList;

public class TeacherService {
    private OutherTeacherDao dao = (OutherTeacherDao) BeanFactory.getBean("TtudentDao");


    public void addTeachers(Teacher teacher) {
        dao.addTeachers(teacher);
    }

    public int isExists(String id) {
        ArrayList<Teacher> List = dao.queryTeacher();
        for (int i = 0; i < List.size(); i++) {
            Teacher teacher = List.get(i);
            if (teacher.getId().equals(id)) {
                return i;
            }
        }
        return -1;
    }

    public boolean deleteTeachers(String id) {
        int index = isExists(id);
        if (index >= 0) {
            dao.deleteTeachers(index);
            return true;
        }
        return false;
    }

    public void updateTeacher(int exists, Teacher newteacher) {
        dao.updateTeacher(exists, newteacher);
    }

    public ArrayList<Teacher> queryTeacher() {
        return dao.queryTeacher();
    }
}
